<template>
  <div class="friend" @click="clickHandle">
    <div class="friend-avatar">
      <div class="friend-badge"></div>
      <img class="friend-avatar-img" v-if="friend.avatar" :src="`http://192.168.137.35:8080/files/${friend.avatar}`" alt="" />
    </div>

    <div class="friend-info">
      <div class="friend-info-name">{{friend.nickname || friend.username}}</div>
      <div class="friend-info-mood">{{friend.message}}</div>
    </div>

    <div class="friend-action">
      <i @click.stop="iconClick" class="el-icon-more friend-icon"></i>
    </div>
  </div>
</template>

<script>
import Popover from '../../components/popover';
import Comp from './comp.vue';

export default {
  props: ['friend'],
  methods: {
    clickHandle() {
      this.$emit('chooseChat', this.friend);
    },
    iconClick(e) {
      const rect = e.target.getBoundingClientRect();

      Popover.show({
        top: rect.top,
        left: rect.right + 10,
        data: this.friend,
        content: Comp,
      });
    },
  },
};
</script>

<style>
.friend {
  width: 260px;
  padding: 10px 0;
  margin: 0 10px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #f5f5f5;
}
.friend:hover .friend-icon {
  visibility: visible;
}
.friend-avatar {
  position: relative;
  height: 60px;
  width: 60px;
  border-radius: 5px;
  background-color: #f5f5f5;
}
.friend-avatar-img {
  height: 60px;
  width: 60px;
  border-radius: 5px;
}
.friend-badge {
  position: absolute;
  top: 0;
  left: 0;
}
.friend-avatar-img {
  height: 60px;
  width: 60px;
  border-radius: 5px;
}
.friend-info {
  margin-left: 10px;
  width: 150px;
}
.friend-info-name {
  color: #333;
  font-size: 16px;
  font-weight: bold;
}
.friend-info-mood {
  margin-top: 3px;
  font-size: 12px;
  color: #999;
}
.friend-action {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  position: relative;
}
.friend-icon {
  transform: rotate(90deg);
  color: #666;
  cursor: pointer;
  visibility: hidden;
}
.friend-action-box {
  position: absolute;
  top: 0;
  right: 0;
  width: 100px;
  height: 120px;
  background-color: red;
}
</style>
